package com.masterclient.app.modules.firstpager.fragments.adapters;

import android.graphics.Paint;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.bean.firstpager.GoodProduct;
import com.eoner.baselibrary.utils.GlideUtil;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.managerlibrary.router.AroutePath;
import com.masterclient.app.R;
import com.masterclient.app.widget.WrapContentHeightViewPager;

/**
 * 作者：sean
 * 创建时间：2017/6/12 15:19
 * 功能说明：首页推荐adapter
 */

public class RecommendRecyclerAdapter extends BaseQuickAdapter<GoodProduct.DataBean.ShItemsBean,BaseViewHolder> {

    public RecommendRecyclerAdapter() {
        super(R.layout.view_awesome_goods_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodProduct.DataBean.ShItemsBean item) {
        GlideUtil.displayCircleImage(mContext,item.getSh_brand_logo(),(ImageView) helper.getView(R.id.iv_brand_logo),R.mipmap.user_head_default_icon, ScreenUtils.dp2px(60),ScreenUtils.dp2px(60));

//        if(!TextUtils.isEmpty(item.getSh_brand_logo())){
//            App.picasso.load(item.getSh_brand_logo()).resize(ScreenUtils.dp2px(60),ScreenUtils.dp2px(60)).transform(new CircleBorderTransform(1, R.color.bg_gray)).into((ImageView) helper.getView(R.id.iv_brand_logo));
//        }
        helper.getView(R.id.iv_brand_logo).setOnClickListener(v->{
            ARouter.getInstance().build(AroutePath.STORE_ACTIVITY).withString("store_id",item.getSh_brand_id()).navigation();
        });


        LinearLayout ll_user = (LinearLayout) helper.getView(R.id.ll_user);
        LinearLayout ll_earn = (LinearLayout) helper.getView(R.id.ll_earn);
        TextView tv_price_n = (TextView) helper.getView(R.id.tv_price_n);
        TextView tv_money_earn = (TextView) helper.getView(R.id.tv_money_earn);
        if(!TextUtils.isEmpty(item.getSh_product().getSh_partner_commission())&&0 == Double.valueOf(item.getSh_product().getSh_partner_commission())){
            ll_earn.setVisibility(View.GONE);
            ll_user.setVisibility(View.VISIBLE);
        }else {
            ll_earn.setVisibility(View.VISIBLE);
            ll_user.setVisibility(View.GONE);
            tv_price_n.setText("¥"+item.getSh_product().getSh_show_price());
            tv_money_earn.setText("赚"+item.getSh_product().getSh_partner_commission());
        }


        ((TextView)helper.getView(R.id.tv_goods_title)).setText(item.getSh_name());
        ((TextView)helper.getView(R.id.tv_goods_desc)).setText(item.getSh_subname());

        helper.setText(R.id.tv_show_price,"¥"+item.getSh_product().getSh_show_price());
        helper.setText(R.id.tv_line_price,"¥"+item.getSh_product().getSh_line_price());
        TextView textView = helper.getView(R.id.tv_line_price);
        textView.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG);

        helper.setText(R.id.tv_brand_name,item.getSh_brand_name());
        helper.setText(R.id.tv_start,item.getSh_brand_create_time());

        ((WrapContentHeightViewPager)helper.getView(R.id.awesomeGoodsViewpager)).setAdapter(new GoodProductImagePagerAdapter(mContext,item.getSh_image(),item) );
        helper.setText(R.id.tv_indicator,"1/"+String.valueOf(item.getSh_image().size()));
        ((WrapContentHeightViewPager)helper.getView(R.id.awesomeGoodsViewpager)).addOnPageChangeListener( new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                helper.setText(R.id.tv_indicator,String.valueOf(position+1)+"/"+String.valueOf(item.getSh_image().size()));
            }
            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


}
